package org.study.poi_excel.style;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;

public class CommonExcelStyle {

	/**
	 * 创建默认的列标题的样式
	 * @param workbook
	 * @return
	 */
	public static CellStyle createTitleStyle(Workbook workbook) {
		CellStyle cellStyle = workbook.createCellStyle();
		//设置背景色
		cellStyle.setFillForegroundColor(HSSFColor.LEMON_CHIFFON.index);
		cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
		//设置字体
		Font font = workbook.createFont();
		font.setFontName("黑体");
		font.setFontHeightInPoints((short)12);
		cellStyle.setFont(font);
		//设置表头边框
		cellStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM);
		cellStyle.setBottomBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM);
		cellStyle.setLeftBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderRight(XSSFCellStyle.BORDER_MEDIUM);
		cellStyle.setRightBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderTop(XSSFCellStyle.BORDER_MEDIUM);
		cellStyle.setTopBorderColor(HSSFColor.BLACK.index);
		cellStyle.setAlignment(CellStyle.ALIGN_CENTER_SELECTION);//水平居中
		cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);//垂直居中
		return cellStyle;
	}

}
